package com.authManager.server.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;

import com.authManager.server.service.ISysCodeService;
import com.authManager.server.dao.SysCodeMapper;
import com.authManager.entity.SysCode;

import com.commons.base.model.AdminPage;
import com.commons.base.model.ResultCode;
import com.commons.base.model.ResultData;

/**
 * <p>
 * 【系统编码表】 服务实现类
 * </p>
 *
 * @author 小旋风
 * @since 2018-8-19
 */
@Service
public class SysCodeServiceImpl extends ServiceImpl<SysCodeMapper, SysCode> implements ISysCodeService {

	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(SysCodeServiceImpl.class);

	@Override
	public ResultData<AdminPage<SysCode>> listSysCode(Map<String, Object> paramMap) {
		Page<SysCode> page = new Page<>(Integer.valueOf(String.valueOf(paramMap.get("pageNum"))),
				Integer.valueOf(String.valueOf(paramMap.get("pageSize"))));
		Wrapper<SysCode> entityWrapper = new EntityWrapper<>();

		// 主键
		if (paramMap.get("sysCodeId") != null) {
			entityWrapper.eq("sys_code.sys_code_id", paramMap.get("sysCodeId"));
		}
		// 编码类型
		if (paramMap.get("codeType") != null) {
			entityWrapper.like("sys_code.code_type", String.valueOf(paramMap.get("codeType")));
		}
		// 编码
		if (paramMap.get("code") != null) {
			entityWrapper.like("sys_code.code", String.valueOf(paramMap.get("code")));
		}
		// 编码名称
		if (paramMap.get("name") != null) {
			entityWrapper.like("sys_code.name", String.valueOf(paramMap.get("name")));
		}
		// 编码值
		if (paramMap.get("val") != null) {
			entityWrapper.like("sys_code.val", String.valueOf(paramMap.get("val")));
		}
		this.selectPage(page, entityWrapper);
		return new ResultData.Builder<AdminPage<SysCode>>(ResultCode.success).setData(new AdminPage<SysCode>(page))
				.build();
	}
}
